package com.hualan.servlet;

import com.alibaba.fastjson.JSON;
import com.hualan.bean.PanghuCourierStation;
import com.hualan.dao.impl.StationDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/courierStation/querySearchCourierStationList")
public class CourierStationListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Map<String,Object> map=new HashMap<>();
        StationDaoImpl stationDao=new StationDaoImpl();
        //页数
        String page=req.getParameter("pageNum");
        int pageNum=page==null?1:Integer.parseInt(page);

        //每页条数
       String size=req.getParameter("pageSize");
        int pageSize=page==null?5:Integer.parseInt(size);

        String communityName = req.getParameter("communityName");
        String startTime = req.getParameter("startTime");
        String endTime = req.getParameter("endTime");
        String courierStationName = req.getParameter("courierStationName");

        //根据页数和每页条数获取信息
        List<PanghuCourierStation> list=stationDao.courierStationSelect(courierStationName,startTime,endTime,pageNum,pageSize,communityName);

        //获取总的数据条数
        List<PanghuCourierStation> listCount = stationDao.courierStationSelect(courierStationName, startTime, endTime, 0, 0, communityName);

        map.put("list",list);
        map.put("total",listCount.size());
        resp.getWriter().write(JSON.toJSONString(map));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
